
package presentation;

import javax.swing.ImageIcon;
import java.awt.Graphics;
import java.awt.BorderLayout;
/**
 *
 * @author Andreu Marimon
 */
public class StatisticsView extends GraficConf {
    PresentationController _pCntrl;
    /** Creates new form PreferencesView */
    public StatisticsView(PresentationController pCntrl) {
	super(pCntrl);
	_pCntrl = pCntrl;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        preferencesPanel = new javax.swing.JPanel();
        userButton = new javax.swing.JButton();
        textButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();

        setMaximumSize(new java.awt.Dimension(800, 600));
        setMinimumSize(new java.awt.Dimension(800, 600));

        preferencesPanel.setMaximumSize(new java.awt.Dimension(252, 403));
        preferencesPanel.setMinimumSize(new java.awt.Dimension(252, 403));
        preferencesPanel.setOpaque(false);

        javax.swing.GroupLayout preferencesPanelLayout = new javax.swing.GroupLayout(preferencesPanel);
        preferencesPanel.setLayout(preferencesPanelLayout);
        preferencesPanelLayout.setHorizontalGroup(
            preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 252, Short.MAX_VALUE)
        );
        preferencesPanelLayout.setVerticalGroup(
            preferencesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 403, Short.MAX_VALUE)
        );

        if(_pCntrl.getId() != 0) {
            userButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/userpreferencesbutton.jpg")));
        }
        else {
            userButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/blockeduserpreferencesbutton.jpg"))); // NOI18N
        }
        userButton.setBorderPainted(false);
        userButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/presseduserpreferencesbutton.jpg"))); // NOI18N
        userButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/hoveruserpreferencesbutton.jpg"))); // NOI18N
        userButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userButtonActionPerformed(evt);
            }
        });

        textButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/textbutton.jpg"))); // NOI18N
        textButton.setBorderPainted(false);
        textButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/pressedtextbutton.jpg")));
        textButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/hovertextbutton.jpg")));
        textButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textButtonActionPerformed(evt);
            }
        });

        backButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/backbutton.jpg"))); // NOI18N
        backButton.setBorderPainted(false);
        backButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/pressedbackbutton.jpg"))); // NOI18N
        backButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/imatges/hoverbackbutton.jpg"))); // NOI18N
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addComponent(preferencesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(textButton, 0, 0, Short.MAX_VALUE)
                        .addComponent(userButton, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(backButton, 0, 0, Short.MAX_VALUE))
                .addGap(316, 316, 316))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(162, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(userButton, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(101, 101, 101)
                        .addComponent(backButton, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(preferencesPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void userButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userButtonActionPerformed
		UserStat preferencesPanel2 = new UserStat(_pCntrl);
		preferencesPanel.removeAll();
        preferencesPanel.setLayout(new BorderLayout());
        preferencesPanel.add(preferencesPanel2, BorderLayout.CENTER);
        repaint();
        validate();
    }//GEN-LAST:event_userButtonActionPerformed

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
		_pCntrl.goToEdit();
    }//GEN-LAST:event_backButtonActionPerformed

    private void textButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textButtonActionPerformed
        TextStat preferencesPanel2 = new TextStat(_pCntrl);
        preferencesPanel.removeAll();
        preferencesPanel.setLayout(new BorderLayout());
        preferencesPanel.add(preferencesPanel2, BorderLayout.CENTER);
        repaint();
        validate();
    }//GEN-LAST:event_textButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JPanel preferencesPanel;
    private javax.swing.JButton textButton;
    private javax.swing.JButton userButton;
    // End of variables declaration//GEN-END:variables

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        this.setOpaque(true);
        ImageIcon background;
		String slash = System.getProperty("file.separator");
       String jarPath = System.getProperty("java.class.path");
       int lastDot = jarPath.lastIndexOf(";");
       String aux = jarPath;
       if (lastDot != -1) {
            aux = jarPath.substring(0, lastDot);
       }
       int lastSlash = aux.lastIndexOf(slash);
       String path = aux.substring(0,lastSlash+1);
        background = new ImageIcon(path+slash+"imatges"+slash+"statisticspreferences.jpg")  ;
		g.drawImage(background.getImage(), 0, 0, 800, 600, null );
    }
	public void paint (Graphics g) {
        super.paint(g);
        if (_pCntrl.getId() == 0) {
            userButton.setEnabled(false);
        }

    }
}
